package com.sn.author.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author xiaom
 * @Date 2020/9/21 13:47
 * @Version 1.0.0
 * @Description <0(等待执行) 10(执行中) 20(执行完毕) 30(停止执行) -10(异常退出)>
 **/
public enum TaskEnums {
    AWAIT(0,"等待执行"),
    WORKING(10,"执行中"),
    FINISH(20,"执行完毕"),
    STOP(30,"停止执行"),
    ERR(-10,"异常退出");


    @Getter
    private Integer code;

    @Getter
    private String desc;

    TaskEnums(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Optional<TaskEnums> match(Integer type) {
        return Arrays.stream(TaskEnums.values())
                .filter(t -> t.getCode().equals(type))
                .findFirst();
    }
}
